package com.tuosha.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.tuosha.dao.ToolsDao;
import com.tuosha.model.ToolsEntity;
import com.tuosha.service.ToolsService;



@Service("toolsServiceImpl")
public class ToolsServiceImpl implements ToolsService {
	@Autowired
	private ToolsDao toolsDao;
	
	@Override
	public ToolsEntity queryObject(Integer id){
		return toolsDao.queryObject(id);
	}
	
	@Override
	public List<ToolsEntity> queryList(Map<String, Object> map){
		return toolsDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return toolsDao.queryTotal(map);
	}
	
	@Override
	public void save(ToolsEntity tools){
		Date date=new Date();
		tools.setCreatedAt(date);
		toolsDao.save(tools);
	}
	
	@Override
	public int update(ToolsEntity tools){
		Date date=new Date();
		tools.setUpdatedAt(date);
		return toolsDao.update(tools);
	}
	
	@Override
	public int delete(Integer id){
		return toolsDao.delete(id);
	}
	
	@Override
	public int deleteBatch(Integer[] ids){
		return toolsDao.deleteBatch(ids);
	}

	public int delById(Integer id){
		Date date=new Date();
		ToolsEntity ties= new ToolsEntity();
		ties.setId(id);
		ties.setDeletedAt(date);
		return toolsDao.update(ties);
	}

	public int delPatch(String  tiestr){
		String[] strs = tiestr.split(",");
		if(strs!=null&&strs.length>0){
			for (String str : strs) {
				delById(Integer.parseInt(str));
			}
		}
		return 0;
	}

	public ToolsEntity queryName(String name){
		return toolsDao.queryName(name);
	}
	
}
